package org.odst.transformer;

import java.util.HashMap;
import java.util.Map;

import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odst.formula.ListRange;
import org.odst.parser.Cell;


/**
 * Represents excel worksheet 
 * @author Leonid Vysochyn
 * @author Cyril PODER
 */
public class Sheet {

    Workbook workbook;

    /**
     * POI Excel workbook object
     */
    OdfSpreadsheetDocument oooWorkbook;

    /**
     * POI Excel sheet representation
     */
    OdfTable oooSheet;
    /**
     * This variable stores all list ranges found while processing template file
     */
    private Map<String, ListRange> listRanges = new HashMap<String, ListRange>();
    /**
     * Stores all named HSSFCell objects
     */
    private Map<String, Cell> namedCells = new HashMap<String, Cell>();

    Configuration configuration = new Configuration();
    
    private Map<String, Object> beanParams = new HashMap<String, Object>();

    public Sheet() {
    }

    public Sheet(OdfSpreadsheetDocument hssfWorkbook, OdfTable hssfSheet, Configuration configuration) {
        this.oooWorkbook = hssfWorkbook;
        this.oooSheet = hssfSheet;
        this.configuration = configuration;
    }

    public Sheet(OdfSpreadsheetDocument hssfWorkbook, OdfTable hssfSheet) {
        this.oooWorkbook = hssfWorkbook;
        this.oooSheet = hssfSheet;
    }

    public String getSheetName(){
        return sheetName;
    }

    public void setSheetName(String sheetName){
        this.sheetName = sheetName; 
    }

    String sheetName;

    public void initSheetName(){
    	sheetName = oooSheet.getTableName();
        if( sheetName.indexOf(' ') >=0 ){
            sheetName = "'" + sheetName + "'";
        }
    }
    
    public void setBeanParams(Map<String, Object> beanParams) {
    	this.beanParams = beanParams;
    }
    
    public Map<String, Object> getBeanParams() {
    	return beanParams;
    }

    public OdfSpreadsheetDocument getHssfWorkbook() {
        return oooWorkbook;
    }

    public void setHssfWorkbook(OdfSpreadsheetDocument hssfWorkbook) {
        this.oooWorkbook = hssfWorkbook;
    }

    public void setOooSheet(OdfTable hssfSheet) {
        this.oooSheet = hssfSheet;
    }

    public OdfTable getOooSheet() {
        return oooSheet;
    }

    public Configuration getConfiguration() {
        return configuration;
    }

    public Map<String, ListRange> getListRanges() {
        return listRanges;
    }

    public Map<String, Cell> getNamedCells() {
        return namedCells;
    }

    public Workbook getWorkbook() {
        return workbook;
    }

    public void setWorkbook(Workbook workbook) {
        this.workbook = workbook;
    }

    public void addNamedCell(String label, Cell cell){
        namedCells.put( label, cell );
    }

    public void addListRange(String name, ListRange range){
        listRanges.put( name, range );
    }

    public int getMaxColNum(){
    	return oooSheet.getColumnCount();
    }


}
